package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.basebean.ListPageBean;
import com.byt.framlib.basemvp.boby.FormBodys;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.google.gson.JsonObject;
import com.lzm.ydpt.entity.mall.MallOrderBean;
import com.lzm.ydpt.entity.riding.OrderBean;
import com.lzm.ydpt.module.mall.fragment.MallOrderListFragment;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.MallOrderListContract;
import com.lzm.ydpt.mvp.modelimpl.MallOrderListModelImpl;

import java.util.List;
import java.util.Map;

/**
 * 类名称：XhXnOrderPresenterImpl
 * 类描述：代理实现
 */
public class MallOrderListPresenterImpl extends BasePresenter implements MallOrderListContract.Presenter {

    private MallOrderListContract.View mView;
    private MallOrderListContract.Model mModel;

    public MallOrderListPresenterImpl(MallOrderListFragment context) {
        super(context.getActivity());
        this.mView = context;
        this.mModel = new MallOrderListModelImpl();
    }

    @Override
    public void onOrderList(FormBodys formBodys) {
        mManager.http(mModel.onOrderList(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<ListPageBean<MallOrderBean>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<ListPageBean<MallOrderBean>> entity) {
                mView.onOrderList(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showErrorView(e.getDisplayMessage());
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showErrorView(entity.getMessage());
            }
        }, "onOrderList"));
    }

    @Override
    public void onDeleteOrder(FormBodys formBodys, int position) {
        mManager.http(mModel.onDeleteOrder(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onDeleteOrder(entity.getMessage(), position);
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onDeleteOrder"));
    }

    @Override
    public void onOrderReceipt(FormBodys formBodys, int position) {
        mManager.http(mModel.onOrderReceipt(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onOrderReceipt(entity.getMessage(), position);
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onOrderReceipt"));
    }

    @Override
    public void onOrderCancel(FormBodys formBodys, int position) {
        mManager.http(mModel.onOrderCancel(formBodys), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<Object>() {
            @Override
            public void onLoadingResult(BaseResponseBean<Object> entity) {
                mView.onOrderCancel(entity.getMessage(), position);
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onOrderCancel"));
    }
}